home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / glibc108.gz / glibc108 / glibc-1.08.1 / manual / examples / popen.c < prev    next >
C/C++ Source or Header  |  1994-02-16  |  527b  |  34 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void 
  5. write_data (FILE * stream)
  6. {
  7.   int i;
  8.   for (i = 0; i < 100; i++)
  9.     fprintf (stream, "%d\n", i);
  10.   if (ferror (stream))
  11.     {
  12.       fprintf (stderr, "Output to stream failed.\n");
  13.       exit (EXIT_FAILURE);
  14.     }
  15. }
  16.  
  17. /*@group*/
  18. int
  19. main (void)
  20. {
  21.   FILE *output;
  22.  
  23.   output = popen ("more", "w");
  24.   if (!output)
  25.     {
  26.       fprintf (stderr, "Could not run more.\n");
  27.       return EXIT_FAILURE;
  28.     }
  29.   write_data (output);
  30.   pclose (output);
  31.   return EXIT_SUCCESS;
  32. }
  33. /*@end group*/
  34.